1
|
|
|
import axios from 'axios'; |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
|
5
|
|
|
export default class CommentsApi { |
6
|
|
|
|
7
|
|
|
constructor(baseUrl = '/comments/') { |
8
|
2 |
|
this.axios = axios.create({ |
9
|
|
|
baseURL: baseUrl |
10
|
|
|
}); |
11
|
|
|
|
12
|
2 |
|
this.axios.defaults.headers.common['Accept'] = 'application/json'; |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
getComments(model, id, parentId = null, params = {}) { |
16
|
|
|
let url = model + '/' + id; |
17
|
|
|
|
18
|
4 |
|
if (parentId !== null) { |
19
|
|
|
url = url + '/' + parentId |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
return this.axios.get(url, { |
23
|
|
|
params: params |
24
|
|
|
}); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
getCommentsBefore(model, id, parentId = null, time, params = {}) { |
28
|
|
|
params.before = time; |
29
|
|
|
return this.getComments(model, id, parentId, params); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
getCommentsAfter(model, id, parentId = null, time, params = {}) { |
33
|
|
|
params.after = time; |
34
|
|
|
return this.getComments(model, id, parentId, params); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
add(model, id, data) { |
38
|
|
|
return this.axios.post(model + '/' + id, data); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
remove(model, id, commentId) { |
42
|
|
|
return this.axios.delete(model + '/' + id + '/' + commentId); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
update(model, id, commentId, data) { |
46
|
|
|
this.axios.patch(model + '/' + id + '/' + commentId, data) |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|